<script type="text/javascript" src="<?=base_url()?>js/popup.js"></script>
<link href="<?=base_url()?>css/popup.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<?=base_url()?>js/jquery.lightbox-0.5.js"></script>
<link href="<?=base_url()?>css/jquery.lightbox-0.5.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="<?=base_url()?>js/jquery.tooltip.js"></script>
<link rel="stylesheet" type="text/css" href="<?=base_url()?>css/jquery.tooltip.css" media="screen" />
<script>
$j(function() {
	$j('.gallery a').lightBox();
	$j('.pic a').lightBox();
	$j('.each *').tooltip({
		showURL: false
	});
	$j(document).ready(function(){
				
	//CLOSING POPUP	
	//Click out event!
	$j("#background-popup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$j(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

}); 
	
});
/*
function tellfriend() {
	$j('#tell-friend').show();
	$j('#popup-shopping').hide();
	centerPopup();
	loadPopup();
}
function sendfriend() 
{
	var friend_name = $j('#friend_name').val();
	var friend_email = $j('#friend_email').val();
	var your_name = $j('#your_name').val();
	var your_email = $j('#your_email').val();
	var your_message = $j('#your_message').val();
	$j.ajax({
		url: '<?=base_url()?>store/tellfriend/',
		type: 'POST',
		data: ({friend_name:friend_name,friend_email:friend_email,your_name:your_name,your_email:your_email,your_message:your_message,current_url:'<?=current_url()?>'}),
		dataType: "html",
		success: function(html) {
			$j('#sendmessage').html(html);
			$j('#friend_name').val('');
			$j('#friend_email').val('');
		}
	})
}
*/
function toObject(arr) {
  var rv = {};
  for (var i = 0; i < arr.length; ++i)
    if (arr[i] !== undefined) rv[i] = arr[i];
  return rv;
}

function addtocart() {
	var quantity=$j('#quantity').val();
	if(quantity == '')
	{
		alert('Please enter a valid number for quantity');
		return false;
	}
	else
	{
		if(isNaN(quantity))
		{
			alert('Please enter a valid number for quantity');
		return false;
		}
		else
		{
			if(quantity <=0 )
			{
				alert('Please enter a valid number for quantity');
		return false;
			}
		}
	}
	var attributes = '';
	//var myArray = new Array();
	var myObject = new Object();
	var num = 0;
	<?php for($i=0;$i<count($attributes);$i++) 
	{ ?>
	 // use json javascript generator and pass value in json format(by Hieu)
	 //myArray[<?=$i?>] = $j('#attribute-<?=$i?>').val();
	
	 myObject.<?=$attributes[$i]['name']?> = $j('#attribute-<?=$i?>').val();
	 // alert('<?=$attributes[$i]['name']?>');
	<?php } ?>
	
	if($j('#sizeproduct').length)
	{
	  mul_size = $j('#sizeproduct').val();
	
		myObject.Size = mul_size;
	}
	//alert(mul_size);
	//var myObject = toObject(myArray);
	attributes = JSON.stringify(myObject);
	//attributes = JSON.stringify(myArray);
	$j.ajax({
		url: '<?=base_url()?>store/addtocart/',
		type: 'POST',
		data: ({quantity:quantity,product_id:<?=$product['id']?>,attributes:attributes}),
		dataType: "html",
		success: function(html) {
			updatecart();
			updatenumberitems();
			$j('#content-pop').html(html);
			$j('#tell-friend').hide();
	        $j('#popup-shopping').show();
			centerPopup();
	loadPopup();
			//alert(html);
		}
	})
}
/*
function addtocart2() {
	
	var attributes = '';
	
	//var myArray = new Array();
	var myObject = new Object();
	<?php for($i=0;$i<count($attributes);$i++) 
	{ ?>
	 // use json javascript generator and pass value in json format(by Hieu)
	 //myArray[<?=$i?>] = $j('#attribute-<?=$i?>').val();
//myObject.attribute<?=$i?> = $j('#attribute-<?=$i?>').val();
 myObject.<?=$attributes[$i]['name']?> = $j('#attribute-<?=$i?>').val();
	<?php } ?>
	if($j('#sizeproduct').length)
	{
	  mul_size = $j('#sizeproduct').val();
	
		myObject.Size = mul_size;
	}
	//var myObject = toObject(myArray);
	attributes = JSON.stringify(myObject);
	$j.ajax({
		url: '<?=base_url()?>store/addtocart/',
		type: 'POST',
		data: ({product_id:<?=$product['id']?>,attributes:attributes}),
		dataType: "html",
		success: function(html) {
			updatecart();
			updatenumberitems();
			$j('#content-pop').html(html);
			$j('#tell-friend').hide();
	        $j('#popup-shopping').show();
			centerPopup();
	loadPopup();
			//alert(html);
		}
	})
}
*/
</script>
<div id="popup-box">
  <!--
	<div id="tell-friend" style="display:none">
    	<div class="close"><a href="javascript:disablePopup()"><img src="<?=base_url()?>img/CloseButton-Up.png" alt="Close" /></a></div>
        <div style="clear:both"></div>
        <div style="clear:both;padding-top:14px">
        <form>
        <table cellpadding="0" cellspacing="0" border="0">
          <tr><td width="180">Name of your friend</td>
              <td><input type="text" class="rounded" id="friend_name" /></td>
          </tr>
          <tr><td height="40">Email of your friend</td>
              <td><input type="text" class="rounded" id="friend_email" /></td>
           </tr>
           <tr><td height="40">Your name</td>
               <td><input type="text" class="rounded" id="your_name" /></td>
           </tr>
           <tr><td height="40">Your email</td>
        	<td><input type="text" class="rounded" id="your_email" /></td>
           </tr>
           <tr><td height="40">Your message</td>
               <td><input type="text" class="rounded" id="your_message" /></td>
            </tr>
         </table>
         </form>
        </div>
        
        <div class="send"><a href="javascript:sendfriend()"><img src="<?=base_url()?>img/SendButton.jpg" alt="Send" /></a></div>
        <div id="sendmessage"></div>
        <div style="clear:both"></div>
        <br/>
    </div>-->
    <div id="popup-shopping" style="display:none;">
    	<div class="close"><a href="javascript:disablePopup()"><img src="<?=base_url()?>img/CloseButton-Up.png" alt="Close" /></a></div>
        <div style="clear:both"></div>
        <div style="clear:both;padding-top:54px">
           <div id="content-pop" style="width:400px;margin:0 auto"></div>
        </div>
        <br/>
    </div>
</div>
<div id="background-popup"></div>

        <div id="store">
            <div class="prod">
            	<div class="pic"><a href="<?=base_url()?>uploads/products/<?=md5('mbb'.$product['id'])?>/<?=$hero['name']?>"><img src="<?=base_url()?>uploads/products/<?=md5('mbb'.$product['id'])?>/thumb1/<?=$hero['name']?>" /></a></div>
                <div class="details">
                  <div style="min-height:385px">
                   <div id="product-name-container"><div style="padding-right:8px;padding-top:8px"><?=$product['title']?></div>
                   </div>
                    <div id="product-desc-title">Item Description</div>
                    <div id="product-desc"><?=$product['long_desc']?></div>
                    <?php if($product['multiplesize']==1)
					{
						$multiple_stock = json_decode($product['size'],true);
						echo '<div class="product-info-row">';
					?>
						<dl><dt>Size</dt>
                	    	<dd><select name="sizeproduct" id="sizeproduct" >
									<?php if($multiple_stock['XXXS']>=1){?><option value="XXXS">XXXS</option><?php }?>
									<?php if($multiple_stock['XXS']>=1){?><option value="XXS">XXS</option><?php }?>
									<?php if($multiple_stock['XS']>=1){?><option value="XS">XS</option><?php }?>
									<?php if($multiple_stock['S']>=1){?><option value="S">S</option><?php }?>
									<?php if($multiple_stock['M']>=1){?><option value="M">M</option><?php }?>
									<?php if($multiple_stock['L']>=1){?><option value="L">L</option><?php }?>
									<?php if($multiple_stock['XL']>=1){?><option value="XL">XL</option><?php }?>
									<?php if($multiple_stock['XXL']>=1){?><option value="XXL">XXL</option><?php }?>
									<?php if($multiple_stock['3XL']>=1){?><option value="3XL">3XL</option><?php }?>
									<?php if($multiple_stock['4XL']>=1){?><option value="4XL">4XL</option><?php }?>
                                    <?php if($multiple_stock['5XL']>=1){?><option value="5XL">5XL</option><?php }?>
                                    <?php if($multiple_stock['6XL']>=1){?><option value="6XL">6XL</option><?php }?>
                                    <?php if($multiple_stock['6']>=1){?><option value="6">6</option><?php }?>
                                    <?php if($multiple_stock['8']>=1){?><option value="8">8</option><?php }?>
                                    <?php if($multiple_stock['10']>=1){?><option value="10">10</option><?php }?>
                                    <?php if($multiple_stock['12']>=1){?><option value="12">12</option><?php }?>
                                    <?php if($multiple_stock['14']>=1){?><option value="14">14</option><?php }?>
                                    <?php if($multiple_stock['16']>=1){?><option value="16">16</option><?php }?>
                                    <?php if($multiple_stock['18']>=1){?><option value="18">18</option><?php }?>
                                    <?php if($multiple_stock['20']>=1){?><option value="20">20</option><?php }?>
                                    <?php if($multiple_stock['22']>=1){?><option value="22">22</option><?php }?>
               	        	</select>
            	            </dd>
        	            </dl>
					<?php
					    echo '</div>'; 
					} ?>
                  <?php 
				  if($attributes != NULL)
				  {
					 
					$n = 0; 
					foreach($attributes as $attribute) 
					{
	                   echo '<div class="product-info-row">'; 
					?>
                    <dl><dt><?=$attribute['name']?></dt>
                    	<dd><select id="attribute-<?=$n?>">
                        	<?php
							$options = $this->Product_model->get_attribute($attribute['id']); 
							foreach($options as $option) { ?>
                            	<option value="<?=$option?>"><?=$option?></option>
                            <?php } ?>
                        	</select>
                        </dd>
                    </dl>
                    <?php $n++; 
					    echo '</div>';
					}
					 
				  } ?>
                    <div class="product-info-row" style="padding-top:20px">
                    <?php 
					/*
					$tax = $this->System_model->get_tax(1);
					if($tax != NULL)
					{ 
					  if($tax['actived'])
					  {
				    	if ($tax['included']) 
					   { 
						if($product['sale_price'] < $product['price']) 
						{ 
							$price = money_format('%i',$product['price']);
							$sale_price = money_format('%i',$product['sale_price']); ?>
						<dl><dt>Price <span class="price">$<?=$price?></span></dt><dd style="width:220px;line-height:16px"><span class="sale_price">Sale Price $<?=$sale_price?></span></dd></dl>
						<?php } else { 
							$price = money_format('%i',$product['price']); ?>
						<p>Price <span class="normal">$<?=$price?></span></p>
						<?php 
						} 
					   } 
					   else 
					   {
						if($product['sale_price'] < $product['price']) 
						{ 
							$price = money_format('%i',$product['price'] * 1.1 );
							$sale_price = money_format('%i',$product['sale_price'] * 1.1); ?>
						<dl><dt>Price <span class="price">$<?=$price?></span></dt><dd style="width:221px;;line-height:16px"><span class="sale_price">Sale Price $<?=$sale_price?></span></dd></dl>
						<?php } else { 
							$price = money_format('%i',$product['price'] * 1.1); ?>
						<p>Price <span class="normal">$<?=$price?></span></p>
						<?php 
						}
					   }
					  }
					}
					else
					{ 
					*/
					  if($product['sale_price'] < $product['price']) 
						{ 
							$price = money_format('%i',$product['price']);
							$sale_price = money_format('%i',$product['sale_price']); ?>
						<div style="float:right;"><div style="float:left;width:160px;line-height:2.5em;">Price <span class="price">$<?=$price?></span></div><div style="float:right;width:210px;"><span class="sale_price">Sale Price $<?=$sale_price?></span></div></div>
						<?php } else { 
							$price = money_format('%i',$product['price']); ?>
						<p>Price <span class="normal">$<?=$price?></span></p>
						<?php 
						} 
					//}
					?>
					  
					
                    </div>
                  </div>
                <div>
                   <div style="text-align:right;float:right">
                     <table cellpadding="0" cellspacing="0" border="0">
                       <tr><td>Quantity</td><td width="10">&nbsp;</td><td><input style="border:1px solid #E5E5E5;height:29px;width:150px;" type="text" name="quantity" id="quantity" value="1" /></td><td><img onclick="addtocart()" src="<?=base_url()?>img/add-button.png" alt="Add" /></td>
                       </tr>
                      </table>
                   </div>
                   <div style="clear:both"></div>
                   <div id="product-buttons">
                    <table cellpadding="0" cellspacing="0" border="0" width="209">
                      <tr>  
                       <td><a href="<?=base_url()?>store/category/1"><img src="<?=base_url()?>img/keep-shopping-button.png" alt="Keep Shoppping" /></a></td>
                       <!--<td><a href="javascript:tellfriend()"><img src="<?=base_url()?>img/tell-friend-button.png" alt="Tell A Friend" /></a></td>
                       <td><a href="javascript:addtocart2()"><img src="<?=base_url()?>img/add-to-basket-medium-button.png" alt="Add To Basket" /></a></td>-->
                       <td width="50"><a href="<?=base_url()?>store/checkout"><img src="<?=base_url()?>img/checkout-button.png" alt="Checkout" /></a></td>
                      </tr>
                     </table>
                  </div>
                </div>
               </div>
            </div>
            <!--
            <div class="more gallery">
               <?php $n = 0; foreach($photos as $photo) { $n++; ?>
                        <div><a href="<?=base_url()?>uploads/products/<?=md5('mbb'.$product['id'])?>/<?=$photo['name']?>"><img src="<?=base_url()?>uploads/products/<?=md5('mbb'.$product['id'])?>/thumb3/<?=$photo['name']?>"<?php if($n>3) print ' class=" hidden"';?> /></a></div>
                        <?php } ?>
                    </div>
                    -->
            <div class="cross">
            	<?php if($crosssales) 
				{ 
                  foreach($crosssales as $item) 
					{
                        echo '<div class="each">';
						$thumb = $this->Product_model->thumb_photo($item['related']);
                        $other = $this->Product_model->identify($item['related']); ?>
                        <a href="<?=base_url()?>store/product/<?=$item['related']?>"><img src="<?=base_url()?>uploads/products/<?=md5('mbb'.$item['related'])?>/thumb3/<?=$thumb['name']?>" title="<?=$other['title']?>" /></a>
                    <?php 
					  echo '</div>';
					  } ?><div style="clear:both"></div><p style="text-align:right;font-weight:bold">You may also like these</p>
                <?php 
				} ?>
            </div>
            <div style="clear:both"></div>
        </div>
                    <table>
            	<tr>
                	
                    	<?php $n = 0; foreach($photos as $photo) { $n++; ?>
                        <td style="border: 1px solid #E5E5E5;float:left;width:101px;height:105px;margin-right:3px;padding:2px;"><a href="<?=base_url()?>uploads/products/<?=md5('mbb'.$product['id'])?>/<?=$photo['name']?>"><img src="<?=base_url()?>uploads/products/<?=md5('mbb'.$product['id'])?>/thumb3/<?=$photo['name']?>"<?php if($n>3) print ' class=" hidden"';?> /></a></div>
                        <?php } ?>
                    </td>
                    
                </tr>
            </table>
